package com.light.buttons;

import javax.microedition.khronos.opengles.GL10;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.hardware.Sensor;
import android.hardware.SensorEvent;

import com.badlogic.gdx.math.Vector2;
import com.huw.cameramanagers.BlackStartEndActivity;
import com.light.music.BackGroundMusicController;
import com.light.roller.BigMenu;
import com.light.roller.BigMenuWorld1;
import com.light.roller.BigMenuWorld2;
import com.light.roller.Choose1;
import com.light.roller.Direction;
import com.light.roller.Launcher;
import com.light.roller.MainMenu;
import com.light.roller.ResourceManager;
import com.light.roller.Roller;

public class StartButton extends Button {

	private Vector2 m_spritePosition;
	public Vector2 getSpritePosition() { return m_spritePosition; }
	
	public StartButton(BaseGameActivity game) {
		super(game);
	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {
		
		
	}

	@Override
	public void onSensorChanged(SensorEvent event) {

		
	}

	@Override
	public void onUpdate(float pSecondsElapsed) {
		
	}

	@Override
	public void reset() {

	}

	@Override
	public void onLoadResources() {
		ResourceManager.onLoadResources("Black", m_game);
		this.m_textureRegion = ResourceManager.getTextureRegion("Black");
	}
	@Override
	public void unLoadResources() {
		this.m_textureRegion = null;
		ResourceManager.unLoadResources("Black", m_game);
	}
	
	@Override
	public void setByCameraPosition(float x, float y) {
		
		
	}

	@Override
	public void onLoadEngine() {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void onLoadScene(Scene scene, PhysicsWorld physicsWorld) {
		
		int centerX = (int)(Roller.CAMERA_WIDTH * 0.27f - this.m_textureRegion.getWidth() / 2);
        int centerY =  (int)(Roller.CAMERA_HEIGHT * 0.3f - this.m_textureRegion.getHeight() / 2);

        
		m_sprite = new Sprite(centerX, centerY, this.m_textureRegion)
		{
			@Override
        	public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY)
        	{
				if (pSceneTouchEvent.isActionUp())
				{
					BackGroundMusicController.turnOffOnPause = false;
					((BlackStartEndActivity)m_game).startMenu(MainMenu.class);
				}
				return true;
        	}
		};
        m_sprite.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
        m_sprite.setAlpha(0.0f);
        m_sprite.setSize(230, 100);
        
		scene.registerTouchArea(m_sprite);
		scene.attachChild(m_sprite);
		
		
	}

	@Override
	public void removeFromScene(Scene scene, PhysicsWorld physicsWorld) {
		scene.unregisterTouchArea(m_sprite);
		scene.detachChild(m_sprite);

		m_sprite = null;
	}

	@Override
	public void rotate(float angle) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void initializeDirection(Direction direction) {
		// TODO Auto-generated method stub
		
	}

}
